# -*- coding:utf-8 -*-
# @File       :   二分模板.py
# @Author     :   LINING
# @Time       :   2024/3/1 15:07
# @Description :   前驱型，后继型

a = [1,2,3,5,7,9,11,13,15,17,19]
b = 19


def get_index_next(target, target_list):
    # 取第一个大于的下标，没有返回len(target_list)
    left = 0
    right = len(target_list)
    while left < right:
        # 向下取整
        mid = int((left+right)/2)
        # 小于等于不是答案可以排掉
        if target_list[mid] <= target:
            left = mid+1
        # 大于可能是答案要保留
        else:
            right = mid
    return right


def get_index_pre(target, target_list):
    # 取第最后一个小于的下标，没有返回-1
    left = -1
    right = len(target_list)-1
    while left < right:
        # 向上取整
        mid = int((left+right+1)/2)
        # 小于等于可能是答案可要保留
        if target_list[mid] <= target:
            left = mid
        # 大于一定不是答案可以删除
        else:
            right = mid-1
    return right


x = get_index_next(17, a)
print(x)

